<template>
	<view class="container">
		<u--form :model="formModel" ref="fromRules" label-width='100'>
			<u-form-item label="店铺logo" borderBottom @click='upload'>
				<image style="width: 140rpx;height: 140rpx;border-radius: 70rpx;" :src="formModel.logoModel.url || 'https://ky.railshj.cn/protocol/icon/images/mine/mine_avatar.png'"
				 mode="aspectFill"></image>
			</u-form-item>
			<u-form-item label="店铺名称" prop="name" borderBottom rightIcon='arrow-right'><u--input v-model="formModel.name" placeholder='请输入昵称' maxlength='8' border="none"/></u-form-item>
		</u--form>
		<view class="footer">
			<jc-button :width="600" title='保 存' @click='submit' backgroundColor="#d4a781"></jc-button>
		</view>
	</view>
</template>

<script>
	import { shop } from '@/api/shop.js'
	import simpleAddress from '@/components/simple-address/simple-address.vue';
	import {uploadFileToService} from '@/common/utils/uploadFile.js'
	import { common } from '@/api/common.js'
	export default{
		components:{ simpleAddress},
		data() {
			return {
				formModel: {},
			}
		},
		onLoad() {
			this.getItemByUserId()
		},
		onShow() {
		},
		onReady() {
			
		},
		methods:{
			
			upload(){
				uploadFileToService().then(res=>{
					if(res.code==10000){
						this.formModel.logo = res.data.image.id
						this.formModel.logoModel.url = res.data.image.url
					}
				})
			},
			//提交表单
			submit() {
				this.updateShopInfo()
			},
			
			updateShopInfo(){
				common.operateActionPost('/merchant/shop/updateAction/', {
					obj_id: this.formModel.id,
					logo: this.formModel.logo,
					name: this.formModel.name
				}).then(res => {
					if(res.data.code == 10000){
						this.userInfo = JSON.parse(JSON.stringify(res.data.data))
						uni.navigateBack()
						uni.showToast({
							title: '保存成功',
							icon: 'none'
						})
					}
				})
			},
			getItemByUserId() {
				shop.getShopinfoByUserId({
					userId: this.$storage.getStorageDataSync(this.$store.state.userInfo).id
				}).then(res => {
					if (res.data.code == 10000) {
						this.formModel = res.data.data
					}
				})
			},
		},
	}
</script>

<style lang="scss" scoped>
	.container{
		display: flex;
		flex-direction: column;
		padding: 0 30rpx;
		background-color: #FFFFFF;
		height: 100vh;
	}
	.footer{
		display: flex;
		flex-direction: column;
		align-items: center;
		margin-top: 100rpx;
	}
</style>
